<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="../js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 
    var counter = 2;
 
    $("#addButton").click(function () {
 
	if(counter>5){
            alert("Only 5 textboxes allow");
            return false;
	}   
 
	var newTextBoxDiv = $(document.createElement('div'))
	     .attr("id", 'TextBoxDiv' + counter);
 
 newTextBoxDiv.after().html(
	      '<input type="text" class="txtborder" style="width: 220px;" name="annotation[]' + counter + 
	      '" id="textbox' + counter + '" value="" >');
 
	newTextBoxDiv.appendTo("#TextBoxesGroup");
 

	counter++;
     });
 
     $("#removeButton").click(function () {
	if(counter==2){
          alert("You should not Remove");
          return false;
       }   
 
	counter--;
 
        $("#TextBoxDiv" + counter).remove();
 
     });
 
     $("#getButtonValue").click(function () {
 
	var msg = '';
	for(i=1; i<counter; i++){
   	  msg += "\n Textbox #" + i + " : " + $('#textbox' + i).val();
	}
    	  alert(msg);
     });
  });

</script>
<script type="text/javascript">

function validateBook()
{
	
	var book_title = document.formBook.book_title.value;
	if(book_title=="")
	{
		alert("Book Title Missing.");	
		document.formBook.book_title.focus();
		return false;
	}
	var book_author = document.formBook.book_author.value;
	if(book_author=="")
	{
		alert("Author Name Missing.");	
		document.formBook.book_author.focus();
		return false;
	}
	var no=/^[0-9.]+$/;
	var price = document.formBook.price.value;
	if(!no.test(price))
	{
		alert("Book price Missing.");	
		document.formBook.price.focus();
		return false;
	}
	var isbn = document.formBook.isbn.value;
	if(!no.test(isbn))
	{
		alert("ISBN Missing.");	
		document.formBook.isbn.focus();
		return false;
	}
	var upload = document.formBook.upload.value;
	if(upload!="")
	{
	  var exp = /^.+\.(jpg|gif|jpeg|JPG|JPEG|GIF|png|PNG)$/;
		if (!exp.test(document.formBook.upload.value))
		{				   
			alert("Please Choose JPG OR GIF File");
			return false;
		}	
	}
	var upload = document.formBook.upload.value;
	
	document.formBook.method = "post";
	document.formBook.action = "action_book.php";
	document.formBook.submit;
}
</script>
<?php
	$sql = "select  `book_name`, `book_desc`, `author`, `ISBN`, `publisher`, 
			`edition`, `store_id`, `published_in`,`cover_image`,`price`,`annotation`,`active_status` from books where id='".$_GET['book_id']."'";
	$res = mysql_query($sql) or die(mysql_error()); 
	$data = mysql_fetch_array($res); 
 
  	if($data['active_status'] == "1")
	{
	  $active_status = "checked";
	}
	else {
	 $deactive_status = "checked";
	}
	
	if($_GET['book_id'] == "") {
		$process ="add";
	}
	else {
		$process ="edit";
	}
?>
<table border="0" width="100%" align="center" >
<tr>
	<td width="46%" align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">
    Add Books</span>&nbsp; 
	<!--<input type="button" name="addnew" value="Add New" onclick="return show();" />-->
	</td>
	<td width="40%" align="right" class="font12">
    <a href="index.php?tc=books" class="font12">Manage Books</a></td>
</tr>
<tr>
	<td background="images/topline.gif" colspan="3" height="11"></td>
</tr>    
</table>
<form name="formBook" onsubmit="return validateBook()" enctype="multipart/form-data">
<table width="99%" align="center" border="0"  class="list" cellpadding="5">
  <tbody><tr>
    <td align="right" width="21%" valign="middle" class="font12">Book Title</td>
    
    <td align="left" valign="middle" colspan="2">
     <input type="text" style="width: 220px;" value="<?php echo $data['book_name'];?>" class="txtborder" id="book_title" name="book_title">
    </td>
  </tr>
  
  <tr>
    <td align="right" width="21%" valign="middle" class="font12">Book Author</td>
   
    <td align="left" valign="middle" colspan="2">
     <input type="text" style="width: 220px;" value="<?php echo $data['author'];?>" class="txtborder" id="book_author" name="book_author">
    </td>
  </tr>
  
  <tr>
    <td align="right" width="21%" valign="middle" class="font12">Publisher</td>
    
    <td align="left" valign="middle" colspan="2">
     <input type="text" style="width: 220px;" value="<?php echo $data['publisher'];?>" class="txtborder" id="publisher" name="publisher">
    </td>
  </tr>
 
  <tr>
    <td align="right" valign="middle" class="font12">Edition</td>
  
    <td align="left" valign="middle" colspan="2">
    <input type="text" style="width: 220px;" value="<?php echo $data['edition'];?>" class="txtborder" id="edition" name="edition">
    </td>
  </tr>
  
  <tr>
    <td align="right" valign="middle" class="font12">Price $</td>
   
    <td align="left" valign="middle" colspan="2">
    <input type="text" style="width: 220px;" value="<?php echo $data['price'];?>" class="txtborder" id="price" name="price">
    </td>
  </tr>
  
  <tr>
    <td align="right" valign="middle" class="font12">Published In</td>
   
    <td align="left" valign="middle" colspan="2">
    <input type="text" style="width: 220px;" value="<?php echo $data['published_in'];?>" class="txtborder" id="published_in" name="published_in">
    </td>
  </tr>
  
  <tr>
    <td align="right" valign="top" class="font12">Book Desc</td>
   
    <td align="left" valign="middle" colspan="2">
    <textarea name="maincont" id="maincont" class="textarea" cols="45" rows="8"><?php echo stripslashes($data['book_desc']);?></textarea>
        <script type="text/javascript">CKEDITOR.replace( 'maincont',{skin : 'kama'});</script>
  
    </td>
  </tr>
 
  <tr>
    <td align="right" valign="middle" class="font12">ISBN No.</td>
   
    <td align="left" valign="middle" colspan="2">
    <input type="text" style="width: 220px;" value="<?php echo $data['ISBN'];?>" class="txtborder" id="isbn" name="isbn">
    </td>
  </tr>
  
  <tr>
    <td align="right" valign="middle" class="font12">Annotation</td>
   
    <td align="left" valign="middle" colspan="2">
   <div id='TextBoxesGroup'>
	<div id="TextBoxDiv1">
    <?php if($_GET['book_id']==""){?>
      <input type='text' class='txtborder' style='width: 220px;' id='textbox1' name="annotation[]"  >
      <input type='button' value='Add' style="background-color:#DA3838; border:#DA3838; color:#FFF;" id='addButton'>
<input type='button' style="background-color:#DA3838; border:#DA3838; color:#FFF;" value='Del' id='removeButton'>
	 <?php
     }
	 else
	 {?>
		 <textarea class="txtborder" id="annotation" name="annotation" cols="50" rows="10"><?php echo $data['annotation'];?>
         </textarea>
	<?php }?>
    </div>
</div>
    </td>
  </tr>
  
    <tr>
    <td align="right" valign="middle" class="font12">Cover Image</td>
    
    <td align="left" valign="middle" colspan="2">
    <input type="file" style="width: 220px;"  class="txtborder" id="upload" name="upload">
    <?php if($data['cover_image']!="") {?><img width="30px"  src="../uploads/books/<?php echo $data['cover_image'] ?>"/><?php } ?>
    
    </td>
    
  </tr>  
  
  <tr>
    <td align="right" valign="middle" class="font12">Status</td>
    
    <td align="left" valign="middle" colspan="2">
    <select class="txtborder" id="status" name="status">
    <option value="1" <?php echo $active_status;?>>Activate</option>
    <option value="0" <?php echo $deactive_status;?>>Deactivate</option>
    </select>
    </td>
  </tr>
  
  
  <tr>
    <td align="left" valign="middle">&nbsp;</td>
    
    <td align="left" valign="middle" colspan="2">
    <input type="hidden" name="id" value="<?php echo $_GET['book_id'];?>">
     <input type="hidden" name="process" value="<?php echo $process;?>">
    <input type="submit" name="SubmitPhoto" value="Save"></td>
  </tr>
</tbody></table>
</form>

